<?php
class User
{
	public $Table="user";
	public $UserID;
	public $UserName;
	public $Pass;
	public $UserTypeID;
	
	function loadByKey($id)
	{
		$ob=new ClassConnect();
		$sql="select * from `".$this->Table."` where UserID='".$id."'";
		$row=$ob->singleData($sql);
		$this->UserID=$row['UserID'];
		$this->UserName=$row['UserName'];
		$this->Pass=$row['Pass'];
		$this->UserTypeID=$row['UserTypeID'];
	}
	function getTable($dk)
	{
		$ob=new ClassConnect();
		$sql="select * from `".$this->Table."` $dk";
		$data=$ob->mutiData($sql);
		return $data;
	}
	function travel($dk)
	{
		$arr=array();
		$data=$this->getTable($dk);
		for($i=0;$i<count($data);$i++)
			array_push($arr,$data[$i]['UserID']);
		return $arr;
	}
	function insert($conn)
	{
		$ob=new ClassConnect();
		$field=array("UserID","UserName","Pass","UserTypeID");
		$value=array($this->UserID,$this->UserName,$this->Pass,$this->UserTypeID);
		return $ob->insertData($conn,$this->Table,$field,$value);
	}
	function update($conn)
	{
		$ob=new ClassConnect();
		$field=array("UserID","UserName","Pass","UserTypeID");
		$value=array($this->UserID,$this->UserName,$this->Pass,$this->UserTypeID);
		$where="UserID = '".$this->UserID."'";
		return $ob->updateData($conn,$this->Table,$field,$value,$where);			
	}
	
	function delete($conn)
	{
		$ob=new ClassConnect();		
		$where="UserID = '".$this->UserID."'";
		return $ob->deleteData($conn,$this->Table,$where);
			
	}
	function cbUser($cbname,$selectValue,$action)
	{
		$arr=array();
		$arr=$this->travel("");
		$cb="<select name='$cbname' onChange=\"$action\">";
		$cb.="<option value='' ></option>";
		for($i=0;$i<count($arr);$i++)
		{
			$obj=new User();
			$obj->loadByKey($arr[$i]);
			$sel="";
			if($arr[$i]==$selectValue)
				$sel="selected";
			$cb.="<option value='".$obj->UserID."' $sel>".$obj->UserName."</option>";
		}
		$cb.="</select>";
		return $cb;
	}
}
?>
